<template>
  <div>
    <el-dialog
    @open="onOpen"
    @close="onClose"
    :visible.sync="dialogVisible"
    :title="formLIst.title">
      <el-form ref="goods"
      size="mini"
      label-width="70px"
      >
      <el-form-item
        v-for="(item) in formLIst.formLIst"
        :key="item.id"
        :label="item.name"
        :prop="item.prop">
        <template >
          <div v-if="item.type === 'textarea'">
            <el-input
              :type="item.type"
              :rows="item.rows"
              :placeholder="item.placeholder"
              v-model="item.value"
              >
            </el-input>
          </div>
          <div v-if="item.type === 'input'">
            <el-input v-model="item.value" :placeholder="item.placeholder" clearable>
          </el-input>
          </div>
          <div v-if="item.type === 'picUrl'">
            <el-form-item prop="item.prop">
              <el-upload ref="picUrl" :action="dialogImageUrl"
                list-type="picture-card" :on-success="picUrluploadGallerys" :headers="headers">
                <i class="el-icon-plus"></i>
              </el-upload>
            </el-form-item>
          </div>
          <div v-if="item.type === 'Tag'">
            <el-tag
            type="success"
            size="small"
            >{{ item.list }}</el-tag>
          </div>
        </template>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="close">取消</el-button>
        <el-button type="primary" @click="handelConfirm">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'formLIst',
  components: {},
  props: {
    // from表单 框架
    formLIst: {
      // 接受参数必须是一个 对象 数组
      type: [Object, Array, String],
      // 必填
      required: true
    },
    scope: {
      type: [Array, Object, String]
    }
  },
  data () {
    return {
      // 设置请求头
      headers: {
        'X-Litemall-Admin-Token': localStorage.getItem('token')
      },
      dialogImageUrl: 'http://82.157.146.153:8090/admin/storage/create',
      dialogVisible: false
    }
  },
  computed: {},
  watch: {},
  created () {
  },
  mounted () {
  },
  methods: {
    // 打开
    onOpen () {
      this.dialogVisible = true
    },
    // 关闭清除
    onClose () {
      this.$refs.goods.resetFields()
    },
    // 取消
    close () {
      this.dialogVisible = false
      this.$refs.goods.resetFields()
      this.$emit('update:visible', false)
    },
    // 确定
    handelConfirm () {
      this.$emit('handelConfirm', this.scope)
      this.$refs.goods.resetFields()
      this.dialogVisible = false
    },
    // 图片
    field104BeforeUpload (file) {
      return file
    },
    picUrluploadGallerys (response, file, fileList) {
      console.log(response)
    }
  }
}
</script>

<style>
.el-upload__tip {
  line-height: 1.2;
}

</style>
